import React, { Component } from 'react';
import PropTypes from 'prop-types';
import AdvancedSearch from 'components/advanced-search';
import UniversalReportService
  from 'containers/data-center/report-management/custom-report/graphic/default-value/custom-report.service';
import { connect } from 'react-redux';
import { messages } from 'share/common';


function mapStateToProps(state) {
  return {
    language: state.main.language,
    company: state.login.company,
    tenant: state.login.tenant
  };
}

@connect(mapStateToProps)

class IndexAdvanceSearch extends Component {
  constructor(props) {
    super(props);
    this.state = {
      searchForm: [],
      currentReportPrivate: {}, // 各报表私有配置的载体 (不知道这是干嘛的)
    };
  }

  componentWillMount() {

  }

  componentDidMount() {

  }

  componentWillReceiveProps(nextProps) {
    // if (nextProps.selectCriteriaDataList.length) {
    this.setState({
      searchForm: UniversalReportService.searchFormFactory({
        context: this,
        list: nextProps.selectCriteriaDataList.map((item) => {
          return {
            criteriaCode: item.criteriaCode,
            criteriaName: item.fieldDisplayName || item.columnDisplayName,
            criteriaPropName: `${item.sourceReportId || item.reportId}_${item.criteriaPropName}`,
            defaultValue: item.defaultValue
          };
        })
      })
    });
    // }
  }

  componentWillUnmount() {

  }

  handleSearch = (values) => {
  };

  render() {
    const { searchForm } = this.state;
    const { widget, customReportData, selectCriteriaDataList } = this.props;

    return (
      <div className='index-advance-search' style={{ padding: 20 }}>
        <AdvancedSearch
          onSearch={this.handleSearch}
          title={customReportData && customReportData.reportName}
          onRef={ref => this.advancedSearchRef = ref}
          pinnedList={searchForm.map(item => item.id)}
          searchButton={{ props: { disabled: true }, text: messages('common.search')/*搜索*/ }}
          resetButton={{ props: { disabled: true }, text: messages('common.reset')/*重置*/ }}
          searchForm={searchForm}
          notLoadWhenMount
          hide={['advanced-pinned-list']}
        />
        {selectCriteriaDataList.length === 0 &&
        <div className="place-holder">{messages('basic-10.key163')/*请选择筛选条件*/}</div>
        }
      </div>
    );
  }
}

IndexAdvanceSearch.propTypes = {};

export default IndexAdvanceSearch;
